<?php
define('ROOT_PATH', '/var/www/html/new/d');
include 'common/autoload.php';
include 'common/area.inc.php';//地区数据数组
include 'common/Prod_Common.php';
include 'class/SimpleExcel.class.php';
use \pft\Prod\Product;
use \pft\Member\MemberAccount;
$status = $_REQUEST['status'];
$lvl_limit = array(0, 2, 6, 9);
if(!in_array($_SESSION['dtype'], $lvl_limit)) exit('不合法的身份！');

if($_SESSION['dtype']==6 && \pft\Member\MemberAccount::GetMemType($_SESSION['sid'])!=0) 
    exit('您的上级不是供应商身份，无法发布产品。');

if(empty($_SESSION['com_type'])) {
    $sqlGetComType = "SELECT com_type FROM pft_member_extinfo WHERE fid={$_SESSION['memberID']}";
    $GLOBALS['le']->query($sqlGetComType);
    $GLOBALS['le']->fetch_assoc();
    $_SESSION['com_type'] = $GLOBALS['le']->f('com_type');
}
$currentPage =$_REQUEST["currentPage"]?$_REQUEST["currentPage"]:1;
$pageSize    =$_REQUEST["pageSize"]?$_REQUEST["pageSize"]:5000;
$offset      =($currentPage-1)*$pageSize;
if(!isset($status)) $status = isset($_GET['s']) ? abs($_GET['s']) : 1;
$page_title = $status == 2 ? '仓库中产品' : '自供应产品';

$ticketOption = array(
    'apply_limit'=> $status,
);
if($_SESSION['dtype']==0) $params['applyer'] = $_SESSION['memberID'];
if($_SESSION['dtype']==6) $params['applyer'] = $_SESSION['sid'];
if($_SESSION['dtype']==2) {
    $mem = new MemberAccount($GLOBALS['le']);
    $params['salerid'] = $mem->getAccountById($_SESSION['memberID']);
}


$params['status'] = $status;
$params['limit']  = $offset;
$params['offset'] = $pageSize;


$soap = SoapInit::GetSoapInside();
$obj = new Product($GLOBALS['le'], $soap);
//print_r($params);
$data = $obj->GetProductsList($params, $ticketOption);

// print_r($data);
// exit;


//TODO::获取会员数据
$memberNames = include dirname(__FILE__) . '/module/link_product/Member.cache.php';
// 仓库中的产品
if($status==2) {
    // 获取没有添加门票的产品
    $hideProducts = $obj->GetEmptyProduct($_SESSION['memberID']);
}
// print_r($memberNames);
// exit;
$Excel = array();
$filename='票付通景区';
$Excel[0]['a']='省';
$Excel[0]['b']='市';
$Excel[0]['c']='供应商';
$Excel[0]['d']='景区类型';
$Excel[0]['d1']='景区名称';
$Excel[0]['e']='票类名称';
$Excel[0]['f']='供货价';
$Excel[0]['g']='建议零售价';

$n=0;
$testArr = array(
    200566,100014,100019,123566,200949,123651,100005,200561,501822,123642,
    2,23,54,55,60,64,65,67,81,83,92,94,104,113,469,902,973,1229,1433,1589,1624,1836,1936,1939,2023,2152,2869,3614,3978,4420,4459,4581,4971,5280,
);
$ptype = array(
    'A'=>'景区门票',
    'B'=>'旅游路线',
    'C'=>'度假酒店',
    'F'=>'套票产品',
);
foreach($data['lands'] as $key=>$land){
    if(in_array($land[apply_did],$testArr)) continue;
    if(strpos('a'.$land['title'],'测试')>0) continue;
    $tmp = explode("|",$land['area']);
    if(count($data['tickets'][$land['id']])){
        foreach($data['tickets'][$land['id']] as $k=>$ticket){
            $n++;
            $Excel[$n]['a']=$areas[$tmp[0]];
            $Excel[$n]['b']=$areas[$tmp[1]];
            $Excel[$n]['c']=$memberNames[$land['apply_did']];
            $Excel[$n]['d']=$ptype[$land['p_type']];
            $Excel[$n]['d1']=$land['title'];
            $Excel[$n]['e']=$ticket['title'];
            $Excel[$n]['f']=$ticket['fprice'];
            $Excel[$n]['g']=$ticket['uprice'];;
        }
    }
	

}
$xls = new SimpleExcel('UTF-8', true,'lt');
$xls->addArray($Excel);
$xls->generateXML($filename);
exit;
?>